<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <div th:include="/layout/head :: head"></div>
</head>
<body>

<div th:include="/layout/navbar :: navbar"></div>


<div class="container" style="margin-top: 50px;">
    <div class="panel panel-default">
        <!-- Default panel contents -->
        <div class="panel-heading">
            配置列表
        </div>
        <div class="panel-body">
            <div class="col-lg-12">
                <div class="input-group">
                    <!--<input id="appId" name="appId" type="text" class="form-control" placeholder="应用编号"-->
                    <!--th:value="${appId}"/>-->
                    <select class="selectpicker form-control" data-live-search="true" data-width="auto" id="appId"
                            name="appId" th:remove="all-but-first">
                        <option th:each="entry : ${appIdMap.entrySet()}"
                                th:value="${entry.key}" th:text="${entry.value}"
                                th:selected="${#strings.equals(#httpServletRequest.getParameter('appId'),entry.key)}"></option>
                    </select>
                    <span class="input-group-btn">
                    <button class="btn btn-default" type="button" onclick="search();"><span
                            class="glyphicon glyphicon-search"
                            aria-hidden="true"></span>查 询
                    </button>
                    <a href="/Config/Create" target="_blank" class="btn btn-default"><span
                            class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加</a>
                    </span>
                </div>
            </div>

        </div>

    </div>

    <table class="table table-bordered table table-hover">
        <thead>
        <tr>
            <th width="180">应用编号</th>
            <th width="180">邮箱地址</th>
            <th width="180">手机号</th>
            <th width="100">最后一次更新时间</th>
            <th width="110">执行</th>
        </tr>
        </thead>
        <tbody th:remove="all-but-first">
        <tr th:each="config:${list}" th:id="${config.id}">
            <td style="word-break: break-all; word-wrap:break-word;">
                <a th:href="|javascript:showDetail('${config.appId}');|"
                   th:text="${config.appId}" target="_blank"></a>
            </td>

            <td style="word-break: break-all; word-wrap:break-word;" th:text="${config.emailTo}"></td>
            <td style="word-break: break-all; word-wrap:break-word;" th:text="${config.phoneNumber}"></td>
            <td style="word-break: break-all; word-wrap:break-word;"
                th:text="${#dates.format(config.lastUpdateDatetime, 'yyyy-MM-dd HH:mm:ss')}"></td>


            <td>
                <a th:href="|javascript:editRecord('${config.appId}');|" target="_blank" class="btn btn-default"><span
                        class="glyphicon glyphicon-pencil" aria-hidden="true"></span>编辑</a>
                <a th:href="|javascript:deleteRecord('${config.appId}');|" class="btn btn-default"><span
                        class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除</a>
            </td>
        </tr>
        </tbody>
    </table>
    <div th:include="/layout/footer :: footer"></div>
    <div th:include="/layout/paging :: paging (${totalRecords},${pageSize},${pageIndex})"></div>
</div>

<script language="javascript" type="application/javascript" xmlns:th="http://www.w3.org/1999/xhtml"
        th:inline="javascript">
    function redirectPage(pageIndex) {
        var appId = $("#appId").val().trim();
        /*<![CDATA[*/
        var url = '/config/list?pageIndex=' + pageIndex + '&appId=' + appId;
        /*]]>*/

        window.location.href = url;
    }

    function search() {
        var appId = $("#appId").val().trim();
        redirectPage(1, appId);
    }

    function showDetail(appId) {
        var url = '/config/detail?appId=' + appId;
        window.open(url);
    }

    function editRecord(appId) {
        var url = '/config/edit?appId=' + appId;
        loadPage(url);
    }

    function deleteRecord(appId) {
        bootbox.confirm({
            message: '您真的要删除这条记录吗?',
            buttons: {
                confirm: {
                    label: '确定',
                    className: 'btn-success'
                },
                cancel: {
                    label: '取消',
                    className: 'btn-danger'
                }
            },
            callback: function (result) {
                if (result) {
                    var url = '/config/delete';
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: "appId=" + appId,
                        success: function (result) {
                            eval(result.script);
                        }
                    });
                }
            }
        });


    }
</script>
</body>
</html>

